package com.gw.jpa.controller;

import com.gw.jpa.entity.Student;
import com.gw.jpa.repository.StudentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    @Autowired
    private StudentRepository studentRepository;
    @PostMapping("/student")
    public Student addStudent(Student student){
        Student student1=null;
        student1=studentRepository.save(student);
        return student1;
    }
    @GetMapping("/student/{sid}")
    public Student getStudent(@PathVariable("sid") Integer sid){
        Student student=null;
        student=studentRepository.findById(sid).get();
        return student;
    }
    @PutMapping("/student")
    public Student updateStudent(Student student){
        Student student1=null;
        student1=studentRepository.save(student);
        return student1;
    }
    @DeleteMapping("/student/{sid}")
    public void deleteStudent(@PathVariable("sid") Integer sid){
        studentRepository.deleteById(sid);
    }
    @GetMapping("/student")
    public List<Student> getStudentJquery(){
        List<Student> studentList=null;
        studentList=studentRepository.findAll();
        return studentList;
    }
}
